import sys

from main import Ui_MainWindow
from PyQt5.QtWidgets import *
import pandas as pd
import xlrd

class MainWindow(Ui_MainWindow,QMainWindow):

    def __init__(self):
        super(MainWindow,self).__init__()
        self.setupUi(self)
        self.setWindowTitle("Alisa表格解析器")
        self.pb_deal.clicked.connect(self.deal_file)
        self.pb_add.clicked.connect(self.add_word)
        self.pb_delete.clicked.connect(self.delete_word)

    def deal_file(self):
        input_path = self.te_input_path.toPlainText()
        if not input_path.endswith("\\"):
            input_path+="\\"
        input_file_name = self.te_input_file_name.toPlainText()
        complete_input_file_path = input_path+input_file_name
        out_file_name = self.te_output_name.toPlainText()
        try:
            sheet_book = xlrd.open_workbook(input_path)
        except Exception as e:
            self.show_message('读取数据文件路径错误。\n你好好检查一下。')
            return
        df_dict = dict()
        for sheet in sheet_book.sheets():
            sheet_name = sheet.name
            df_dict[sheet_name] = pd.read_excel(complete_input_file_path,sheet_name,index_col=None,na_values=[''])
        # df = pd.read_excel(path)
        # print(df_dict)
        self.show_message('test_first')


    def add_word(self):
        row = self.table_words.rowCount()
        self.table_words.insertRow(row)
        self.table_words.setItem(row,0,QTableWidgetItem(""))

    def delete_word(self):
        if self.table_words.currentItem():
            row = self.table_words.currentItem().row()
            self.table_words.removeRow(row)



    def show_message(self,message):
        QMessageBox.information(self, "提示", self.tr(message), QMessageBox.Yes)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    client = MainWindow()
    client.show()
    sys.exit(app.exec_())